<?php

namespace Wilead\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Wilead\AdminBundle\Entity\MessageLog;

/**
 * MessageLog controller.
 *
 */
class MessageLogController extends Controller {

    /**
     * Lists all MessageLog entities.
     *
     */
    public function indexAction() {
        $em = $this->getDoctrine()->getManager();
        $filter = $this->get('form.factory')->create(new \Wilead\AdminBundle\Filter\MessageLogFilterType);
        $queryBuilder = $em->getRepository('WileadAdminBundle:MessageLog')->createQueryBuilder('q');
        if ($this->get('request')->query->has('submit-filter')) {
            $filter->bind($this->get('request'));
            $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($filter, $queryBuilder);
        }

        $queryBuilder->orderBy('q.id', 'desc');

        $entities = $queryBuilder->getQuery()->getResult();

        return $this->render('WileadAdminBundle:MessageLog:index.html.twig', array(
                    'entities' => $entities,
                    'filter' => $filter->createView()
        ));
    }

    /**
     * Finds and displays a MessageLog entity.
     *
     */
    public function showAction($id) {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('WileadAdminBundle:MessageLog')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find MessageLog entity.');
        }

        return $this->render('WileadAdminBundle:MessageLog:show.html.twig', array(
                    'entity' => $entity,
        ));
    }

}
